/**
 * 工作流相关类型定义
 */

import { ExecutionMode, StepType } from './enums'

/**
 * 工作流定义
 */
export interface WorkflowDefinition {
  id: number
  name: string
  description: string
  version: string
  isEnabled: boolean
  createdBy: string
  createdAt: string
  updatedAt?: string
  stages?: Stage[]
}

/**
 * Stage 阶段
 */
export interface Stage {
  id: number
  workflowDefinitionId: number
  name: string
  order: number
  executionMode: ExecutionMode
  steps?: Step[]
}

/**
 * Step 步骤
 */
export interface Step {
  id: number
  stageId: number
  name: string
  stepType: StepType
  order: number
  stepConfig: string // JSON 字符串
  timeout?: number
  retryCount?: number
  continueOnError?: boolean
}

/**
 * Step 配置（解析后）
 */
export interface StepConfig {
  [key: string]: any
}

/**
 * Git Clone 步骤配置
 */
export interface GitCloneConfig {
  repository: string
  branch: string
  depth?: number
  submodules?: boolean
}

/**
 * Build 步骤配置
 */
export interface BuildConfig {
  buildTool: string
  command: string
  workingDirectory?: string
  outputDirectory?: string
}

/**
 * Docker Build 步骤配置
 */
export interface DockerBuildConfig {
  dockerfilePath: string
  imageName: string
  imageTag: string
  buildArgs?: Record<string, string>
  context?: string
}

/**
 * 自定义脚本步骤配置
 */
export interface CustomScriptConfig {
  scriptContent: string
  scriptType: 'bash' | 'powershell' | 'python'
  workingDirectory?: string
}

/**
 * 创建工作流请求
 */
export interface CreateWorkflowRequest {
  name: string
  description: string
  version: string
  stages: Omit<Stage, 'id' | 'workflowDefinitionId'>[]
}

/**
 * 更新工作流请求
 */
export interface UpdateWorkflowRequest extends Partial<CreateWorkflowRequest> {
  isEnabled?: boolean
}

/**
 * 工作流验证结果
 */
export interface WorkflowValidationResult {
  isValid: boolean
  errors: string[]
  warnings?: string[]
}
